<template>
<div class="column">
    <div class="swarchBox">
        <img src="https://youyang-cdn.mdshuzhi.com/upload/icon_search@2x.png" />
        <input placeholder="搜索关键词找音频" v-model="searchVal" @keyup.13="goSearch" @confirm="goSearch" />
    </div>
    <div class="lists">
        <scroller :on-infinite="infinite" ref="myscroller" class="scroll">
            <div class="in">
                <div class="left">
                    <router-link :to="item.hasVideo == 1 && item.videoLink ? item.videoLink : '/Playing?categoryId=' +singnavid +'&audioId=' +item.id"
                      v-for="(item,index) in singnavdata" :key="index" class="item" v-if="index%2 == 0">
                        <div class="musicImg">
                            <img :src="item.imgUrl" />
                            <!-- 听 -->
                            <div class="listenBox">
                                <div>{{item.playCount}}播放</div>
                                <template v-if="item.hasVideo==1">
                                    <!-- 外链指定页 -->
                                    <template v-if="item.videoLink">
                                        <div class="listenPic">听</div>
                                    </template>
                                    <!-- 小程序 -->
                                    <template v-else>
                                        <div class="listenPic">听</div>
                                    </template>
                                </template>
                                <div v-else class="listenPic">听</div>
                            </div>
                            <div class="new" v-if="item.isNew==1"></div>
                        </div>
                        <div class="musicWord">
                            <div class="musicTitle">
                                <img src="https://youyang-cdn.mdshuzhi.com/upload/icon_fire@2x.png" v-if="item.isHotPlay==1" />
                                <span>{{item.title || '好先生与皓先生'}}</span>
                            </div>
                            <!-- <div v-if="1" class="lowSongs">{{item.tag || 'jain'}}</div> -->
                            <!-- <div class="songType" v-if="1">
                                <span v-for="(keyItem,index) in 2" :key="index">{{keyItem || 'running'}}</span>
                            </div> -->
                        </div>
                    </router-link>
                </div>
                <div class="right">
                    <router-link :to="item.hasVideo == 1 && item.videoLink ? item.videoLink : '/Playing?categoryId=' +singnavid +'&audioId=' +item.id"
                      v-for="(item,index) in singnavdata" :key="index" class="item" v-if="index%2 != 0">
                        <div class="musicImg">
                            <img :src="item.imgUrl" />
                            <!-- 听 -->
                            <div class="listenBox">
                                <div>{{item.playCount}}播放</div>
                                <template v-if="item.hasVideo==1">
                                    <!-- 外链指定页 -->
                                    <template v-if="item.videoLink">
                                        <div class="listenPic">听</div>
                                    </template>
                                    <!-- 小程序 -->
                                    <template v-else>
                                        <div class="listenPic">听</div>
                                    </template>
                                </template>
                                <div v-else class="listenPic">听</div>
                            </div>
                            <div class="new" v-if="item.isNew==1"></div>
                        </div>
                        <div class="musicWord">
                            <div class="musicTitle">
                                <img src="https://youyang-cdn.mdshuzhi.com/upload/icon_fire@2x.png" v-if="item.isHotPlay==1" />
                                <span>{{item.title || '好先生与皓先生'}}</span>
                            </div>
                            <!-- <div v-if="1" class="lowSongs">{{item.tag || 'rain'}}</div> -->
                            <!-- <div class="songType" v-if="item.keywords && item.keywords.length>0">
                                <span v-for="(keyItem,index2) in item.keywords" :key="index2">{{keyItem }}</span>
                            </div> -->
                        </div>
                    </router-link>
                </div>
            </div>
        </scroller>
    </div>
</div>
</template>

<script>
import controller from "@/components/controllers/controllers";
export default {
    name: "PopSlowSongs",
    data() {
        return {
            searchVal: "",
            singnavdata: [],
            singnavid: "",
            singnavpage: 1,
            singnavpageSize: 10,
            singnavisEnd: false,
            searchVal: "",
        };
    },
    mounted() {
        this.singnavid = this.$route.query.id
        document.title = this.$route.query.title
        this.getAudioList()
        window.addEventListener('mousewheel',this.handleScroll);
    },
    destroyed(){
      window.removeEventListener('mousewheel',this.handleScroll)
    },
    methods: {
        handleScroll(e){
          let that = this  //此this指向的是vue
          console.log(e.wheelDelta)
          if (e.wheelDelta < 0) {
              that.$refs.myscroller && (that.$refs.myscroller.scrollBy(0, 50, true));
          } else {
            that.$refs.myscroller && (that.$refs.myscroller.scrollBy(0, -50, true));
          }
        },
        // 上拉加载
        infinite(done) {
          const that = this
          setTimeout(() => {
            if (that.singnavisEnd) {
                that.$refs.myscroller.finishInfinite(true); //这个方法是不让它加载了，显示“没有更多数据”，要不然会一直转圈圈
            } else {
              console.log("进行下一次加载操作");
              that.singnavisEnd = true;
              done(); //进行下一次加载操作
              that.singnavpage += 1
              that.getAudioList()
            }
          }, 1500);
        },
        //获取音频列表
        getAudioList() {
            let _self = this
            controller.audioList({
                sortBy: 0,
                categoryId: this.singnavid,
                page: this.singnavpage,
                pageSize: this.singnavpageSize,
                tag: this.tag,
            }).then(res => {
                for (let item of res.baseData.list) {
                    if (item.keywords) {
                        item.keywords = item.keywords.split(',')
                    }
                }
                _self.singnavdata = this.singnavdata.concat(res.baseData.list)
                _self.singnavisEnd = res.baseData.lastPage
            })
        },
        //搜索
        goSearch() {
            this.$router.push({
                path: "searchList?search=" + this.searchVal,
            });
        }
    }
};
</script>

<style lang="scss" scoped>
.column {
    // width: 750px;
    min-width: 640px;
    max-width: 960px;
    margin: 0 auto;

    .swarchBox {
        // width: 702px;
				width: 93.6%;
        height: 64px;
        background-color: #f6f6fa;
        color: #a8acbb;
        font-size: 28px;
        border-radius: 32px;
        margin: 0 auto;
        margin-top: 10px;
        overflow: hidden;
        position: relative;

        img {
            position: absolute;
            left: 24px;
            top: 20px;
            width: 25px;
            height: 25px;
        }

        input {
            width: 100%;
            height: 100%;
            background-color: #f6f6fa;
            padding-left: 68px;
            box-sizing: border-box;
            border: none;
            outline: none;
        }
    }

    /* 歌曲列表 */
    .lists {
        overflow: hidden;
        padding: 0 30px;
        height: calc(100vh - 120px);
        position: relative;
        .scroll{
          height: auto !important;
        }
        /deep/ ._v-container{
          top: 32px;
          bottom: 15px;
          ._v-content{
            padding-bottom: 55px;
          }
        }
        .in {
            overflow: hidden;
        }

        .left {
            float: left;
            // width: 330px;
            width: 48%;
            // margin-right: 26px;
            margin-right: 4%;
        }

        .right {
            float: left;
            // width: 330px;
            width: 48%;
        }

        .item {
            position: relative;
            margin-bottom: 32px;
            display: block;

            .musicImg {
                // height: 330px;
                border-radius: 8px;
                overflow: hidden;
                position: relative;

                img {
                    width: 100%;
                    height: 100%;
                    background: #333;
                }

                .listenBox {
                    width: 100%;
                    height: 48px;
                    position: absolute;
                    bottom: 16px;
                    left: 0;
                    padding: 0 16px;
                    box-sizing: border-box;
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    font-size: 20px;
                    color: #fff;

                    .listenPic {
                        width: 48px;
                        height: 48px;
                        border-radius: 50%;
                        font-size: 25px;
                        display: flex;
                        justify-content: center;
                        align-items: center;
                        background-color: #fff;
                        color: rgb(99, 139, 101);
                    }
                }

                .new {
                    position: absolute;
                    z-index: 1;
                    top: 0;
                    left: 0;
                    width: 70px;
                    height: 70px;
                    background: url(https://youyang-cdn.mdshuzhi.com/upload/tag_new.png) no-repeat center center;
                    background-size: 100%;
                    color: #fff;
                    line-height: 70px;
                    text-align: center;
                }
            }

            .musicWord {
                width: 100%;
                margin-top: 20px;
                padding-left: 8px;
                box-sizing: border-box;

                .musicTitle img {
                    width: 24px;
                    height: 28px;
                    margin-right: 16px;
                }

                .musicTitle span {
                    color: #323232;
                    font-size: 28px;
                    line-height: 42px;
                    font-weight: 500;
                }

                .songType span:first-child {
                    background: #fdf1e5;
                    border-radius: 4px;
                    font-size: 20px;
                    color: #f2ab5e;
                    margin-right: 14px;
                    padding: 7px 13px;
                }

                .songType span:nth-child(2) {
                    background: rgba(106, 191, 190, 0.16);
                    border-radius: 4px;
                    color: #6abfbe;
                    font-size: 20px;
                    padding: 7px 13px;
                }
            }
        }

        .lowSongs {
            width: 100%;
            line-height: 40px;
            border-radius: 4px;
            background: rgba(255, 237, 234, 1);
            border: 2px solid rgba(230, 109, 77, 1);
            text-align: center;
            font-size: 20px;
            color: #e66d4d;
            margin: 13px auto;
            box-sizing: border-box;
        }
    }
}
</style>
